import {observable as o, computed as c, action as a} from 'mobx';
import _ from 'lodash';
import axios from 'core/axios';
import RootStore from 'core/Store.js';
import request from 'core/request.js';
import Im from 'immutable';
import {browserHistory} from 'react-router';
import html2canvas from 'html2canvas';

class Store extends RootStore {
    constructor(args) {
        super(args);
    }

    @o visible = false;
    @o codeUrl = '';
    @o downloadName = '';

    will() {

    }

    closeDialog() {
        this.visible = false;
        this.codeUrl = '';
    }

    downloadImage() {
        this.stores.Frame.showLoading();
        setTimeout(() => {
            html2canvas(document.querySelector('#container')).then(canvas => {
                let imgURL = canvas.toDataURL();
                let a = document.createElement('a');
                // document.body.appendChild(canvas);
                a.href = imgURL;
                a.download = this.downloadName;
                a.click();
                this.stores.Frame.hideLoading();
            });
        }, 20);
    }

    copyUrl() {
        this.stores.Message.showMessage(1, '复制成功');
    }

    mount() {
        this.on('qrCodeDialog:show', (data) => {
            this.visible = true;
            if (data) {
                this.codeUrl = data.codeUrl;
                this.downloadName = data.downloadName || '邀请码';
            }
        });
    }

}

export default Store;